package com.kzw.oa.system.model;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
 * 员工与部门
 */
@Entity
@Table(name = "user_org")
public class UserOrg implements Serializable {
	private static final long serialVersionUID = -7219116974377380703L;

	/**
	 * 主要
	 */
	public static final Short PRIMARY = 1;
	/**
	 * 非主要
	 */
	public static final Short NOT_PRIMARY = 0;

	/**
	 * 主负责, 分管
	 */
	public static final Short CHARGE = 1;
	/**
	 * 非负责
	 */
	public static final Short NOT_CHARGE = 0;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "user_org_id")
	private Long userOrgId;

	@ManyToOne
	@JoinColumn(name = "user_id")
	private AppUser appUser;

	@ManyToOne
	@JoinColumn(name = "dept_id")
	private Department dept;

	// 是否主要
	@Column
	private Short isPrimary;

	// 是否主管
	@Column
	private Short isCharge;

	// 加上orgId为了方便Json格式化处理
	@Transient
	public Long orgId;

	public UserOrg() {
	}

	public UserOrg(Long in_userOrgId) {
		this.setUserOrgId(in_userOrgId);
	}

	public AppUser getAppUser() {
		return appUser;
	}

	public void setAppUser(AppUser in_appUser) {
		this.appUser = in_appUser;
	}

	public Department getDept() {
		return dept;
	}

	public void setDept(Department dept) {
		this.dept = dept;
	}

	public Long getUserOrgId() {
		return this.userOrgId;
	}

	public void setUserOrgId(Long aValue) {
		this.userOrgId = aValue;
	}

	public Long getUserid() {
		return this.getAppUser() == null ? null : this.getAppUser().getUserId();
	}

	/**
	 * Set the userid
	 */
	public void setUserid(Long aValue) {
		if (aValue == null) {
			appUser = null;
		} else if (appUser == null) {
			appUser = new AppUser(aValue);
		} else {
			appUser.setUserId(aValue);
		}
	}

	public Long getOrgId() {
		if (orgId == null) {
			orgId = dept == null ? null : dept.getDepId();
		}
		return orgId;
	}

	public void setOrgId(Long aValue) {
		if (aValue == null) {
			dept = null;
		} else if (dept == null) {
			dept = new Department(aValue);
		} else {
			dept.setDepId(aValue);
		}
		orgId = aValue;
	}

	public Short getIsPrimary() {
		return this.isPrimary;
	}

	public void setIsPrimary(Short aValue) {
		this.isPrimary = aValue;
	}

	public Short getIsCharge() {
		return this.isCharge;
	}

	public void setIsCharge(Short aValue) {
		this.isCharge = aValue;
	}

}
